const path = require('path')
var webpack = require('webpack')
function resolve(dir) {
  return path.join(__dirname, dir)
}
module.exports = {
  // 解决qrcode加载失败问题
  runtimeCompiler: true,
  publicPath: process.env.VUE_PUBLICPATH || '/',
  lintOnSave: false,
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@', resolve('src'))
      .set('@static', resolve('src/static'))
      .set('@component', resolve('src/components'))
      .set('@common', resolve('src/components/common'))
      .set('@assets', resolve('src/assets'))
      .set('@utils', resolve('src/utils'))
    config.plugin('provide').use(webpack.ProvidePlugin, [
      {
        $: 'jquery',
        jquery: 'jquery',
        jQuery: 'jquery',
        'window.jQuery': 'jquery'
      }
    ])
    config.module
      .rule('fonts')
      .test(/.(ttf|otf|eot|woff|woff2)$/)
      .use('url-loader')
      .loader('url-loader')
      .tap(() => ({ name: '/fonts/[name].[hash:8].[ext]' }))
      .end()
  },
  devServer: {
    // open: true,
    host: process.env.VUE_APP_HOST,
    port: process.env.VUE_APP_PORT,
    overlay: {
      warnings: true,
      errors: true
    },
    proxy: {
      '/api/polyv': {
        target: 'http://api.polyv.net',
        changeOrigin: true,
        pathRewrite: {
          '^/api/polyv': ''
        }
      },
      '/api/token/get_token': {
        target: 'http://192.168.1.62:8083/api',
        changeOrigin: true,
        pathRewrite: {
          // '^/api': '/api'
          '^/api': ''
        }
      },
      '/api/token/refresh_token': {
        target: 'http://oldpc.dapengjiaoyu.com/api',
        changeOrigin: true,
        pathRewrite: {
          // '^/api': '/api'
          '^/api': ''
        }
      },
      // 标识符: 反向代理配置选项
      '/api': {
        target: process.env.VUE_APP_BASE_URL,
        changeOrigin: true,
        pathRewrite: {
          // '^/api': '/api'
          '^/api': ''
        }
      }
    },
    disableHostCheck: true,
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  },
  configureWebpack: {
    output: {
      // 微应用的包名，这里与主应用中注册的微应用名称一致
      library: 'yunying',
      // 将你的 library 暴露为所有的模块定义下都可运行的方式
      libraryTarget: 'umd',
      // 按需加载相关，设置为 webpackJsonp_yunying 即可
      jsonpFunction: 'webpackJsonp_yunying'
    },
    resolve: {
      alias: {
        // 解决qrcode加载失败问题
        vue$: 'vue/dist/vue.esm.js',
        '@': path.resolve(__dirname, 'src')
      }
    }
  },
  css: {
    extract: { ignoreOrder: true }
  }
}
